In [1]:
%pylab inline
from pyannote.core import Segment, Annotation
from pyannote.core.notebook import notebook
figsize(20, 10)
In [2]:
from pyannote.database import get_database
database = get_database('Etape')
protocol = database.get_protocol('SpeakerDiarization', 'TV')
one_file = next(protocol.train())
In [3]:
reference = one_file['annotation']
timeline = one_file['annotated']
annotation = reference.crop(Segment(500, 1000)).anonymize_labels()
In [4]:
notebook.reset()
timeline
Out[4]:
In [5]:
notebook.reset()
annotation
Out[5]:
In [6]:
def plot_segment_generator(source, generator, N=10):
notebook.reset()
subplot(N+1, 1, 1)
notebook.plot_timeline(source, time=False)
for i, segment in enumerate(generator):
if i == N:
break
subplot(N+1, 1, i+2)
notebook.plot_segment(segment, time=i==(N-1))
tight_layout()
In [9]:
from pyannote.generators.fragment import SlidingSegments
In [15]:
factory = SlidingSegments(duration=300, step=250)
generator = factory.iter_segments(timeline)
plot_segment_generator(timeline, generator, N=9)
In [18]:
factory = SlidingSegments(duration=300, min_duration=10, step=250)
generator = factory.iter_segments(timeline)
plot_segment_generator(timeline, generator, N=13)
In [9]:
def plot_track_generator(source, generator, N=10):
notebook.reset()
subplot(N+1, 1, 1)
notebook.plot_annotation(source, time=False)
for i, yielded in enumerate(generator):
if len(yielded) == 3:
segment, track, label = yielded
else:
segment, label = yielded
track = '_'
if i == N:
break
subplot(N+1, 1, i+2)
annotation = Annotation()
annotation[segment, track] = label
notebook.plot_annotation(annotation, time=i==(N-1), legend=False)
tight_layout()
In [10]:
from pyannote.generators.fragment import SlidingLabeledSegments
In [11]:
a = annotation.crop(Segment(500, 600))
factory = SlidingLabeledSegments(duration=20, step=5)
generator = factory.iter_segments(a)
plot_track_generator(a, generator, N=6)
In [12]:
factory = SlidingLabeledSegments(duration=20, min_duration=5, step=15)
generator = factory.iter_segments(a)
plot_track_generator(a, generator, N=7)
In [13]:
from pyannote.generators.fragment import RandomSegments
factory = RandomSegments(duration=300)
generator = factory.iter_segments(timeline)
In [14]:
plot_segment_generator(timeline, generator, N=10)
In [15]:
from pyannote.generators.fragment import RandomTracks
factory = RandomTracks(yield_label=True)
generator = factory.iter_tracks(annotation)
In [16]:
plot_track_generator(annotation, generator, N=10)
In [17]:
def plot_triplet_generator(source, generator, N=10):
notebook.reset()
subplot2grid((N+1, 3), (0, 0), colspan=3)
notebook.plot_annotation(source, time=False, legend=True)
for i, (anchor, positive, negative) in enumerate(generator):
if i == N:
break
for k, item in enumerate([anchor, positive, negative]):
subplot2grid((N+1, 3), (i+1, k))
annotation = Annotation()
annotation[item[0], '_'] = item[-1]
notebook.plot_annotation(annotation, time=i==(N-1), legend=False)
tight_layout()
In [18]:
from pyannote.generators.fragment import RandomTrackTriplets
factory = RandomTrackTriplets(per_label=3, yield_label=True)
generator = factory.iter_triplets(annotation)
In [19]:
plot_triplet_generator(annotation, generator, N=10)
In [20]:
from pyannote.generators.fragment import RandomSegmentTriplets
factory = RandomSegmentTriplets(per_label=3, duration=5.0, yield_label=True)
generator = factory.iter_triplets(annotation)
In [21]:
plot_triplet_generator(annotation, generator, N=10)
In [22]:
def plot_pair_generator(source, generator, N=10):
notebook.reset()
subplot2grid((N+1, 3), (0, 0), colspan=3)
notebook.plot_annotation(source, time=False, legend=True)
for i, ((query, returned), relevance) in enumerate(generator):
if i == N:
break
for k, item in enumerate([query, returned]):
subplot2grid((N+1, 3), (i+1, k))
annotation = Annotation()
annotation[item[0], '_'] = item[-1]
notebook.plot_annotation(annotation, time=i==(N-1), legend=False)
subplot2grid((N+1, 3), (i+1, 2))
imshow(relevance * np.ones((1, 1)), vmax=1., vmin=0., cmap=cm.Greys)
#text(0.5, 0.5, 'positive' if relevance else 'negative', size=18, ha='center', va='center')
axis('off')
tight_layout()
In [23]:
from pyannote.generators.fragment import RandomSegmentPairs
factory = RandomSegmentPairs(per_label=2, duration=5.0, yield_label=True)
generator = factory.iter_pairs(annotation)
In [24]:
plot_pair_generator(annotation, generator, N=10)